package com.cloudptt.api.comm;


import static android.content.Context.TELEPHONY_SERVICE;

import com.cloudptt.api.models.VersionInfo;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.provider.Settings;
import android.telephony.TelephonyManager;

public class CommInfo {

	public static VersionInfo getVersionInfo(Context ctx) {
		try {
			PackageManager manager = ctx.getPackageManager();
			PackageInfo info = manager.getPackageInfo(ctx.getPackageName(), 0);
			VersionInfo versionInfo = new VersionInfo(info.versionName,info.versionCode);
			return versionInfo;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}


	public static String getImei(Context ctx)
	{
		try {
			String id = "";
			TelephonyManager tm = (TelephonyManager) ctx.getSystemService(TELEPHONY_SERVICE);
			if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
			{
				tm.getImei();
			}
			else
			{
				tm.getDeviceId();
			} // 需 READ_PHONE_STATE 权限
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
		return "";
	}
	public static String getAndroidId(Context ctx)
	{
		String androidId = Settings.Secure.getString(ctx.getContentResolver(), Settings.Secure.ANDROID_ID);
		return androidId;
	}
}
